package com.leyou.item.controller;


import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryBrandService;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    /**
     * 根据父类目id查询子类目的集合
     *
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> findCategoryByid(@RequestParam("pid") Long pid) {
        return ResponseEntity.ok(this.categoryService.findCategoryByid(pid));
    }

    /**
     * 根据id查询分类
     *
     * @return
     */
    @GetMapping("{id}")
    public ResponseEntity<CategoryDTO> queryCategoryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.categoryService.queryCategoryById(id));

    }

    /**
     * 根据分类id集合查询分类集合
     *
     * @param ids
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam("ids") List<Long> ids) {
        return ResponseEntity.ok(CategoryDTO.convertEntityList(categoryService.listByIds(ids)));
    }

    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBrandId(@RequestParam("id") Long brandId) {
        ResponseEntity.ok(categoryService.queryCategoryByBrandId(brandId));
        return null;
    }
}
